<template>
  <div class="index-icons">
    <swiper :options="swiperOption">
       <swiper-slide   v-for="(page,index) of pages" :key="index">
        <div class="icons-img" v-for="item of page" :key="item.id">
          <div class="img-box">
            <img class="icons-content" :src="item.url"/>
          </div>
          <p class="icons-dec">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconsData: Array
  },
  data: function () {
    return {
      swiperOption: {}
    }
  },
  computed: {
    pages: function () {
      const pages = []
      this.iconsData.forEach(function (item, index) {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .index-icons >>> .swiper-container
    width: 100%
    height: 0
    padding-bottom: 50%
  .index-icons
    margin-top: 0.1rem
  .icons-img
    position: relative
    float: left
    overflow: hidden
    width: 25%
    height: 0
    padding-bottom: 25%
    font-size: 0.16rem

    .img-box
      position: absolute
      top: 0
      left: 0
      right 0
      bottom: .44rem
      padding: .1rem

      .icons-content
        display: block
        margin: 0 auto
        height: 100%

    .icons-dec
      position: absolute
      left: 0
      right 0
      bottom: 0
      line-height .44rem
      text-align: center
      color: $darkTextColor
      ellipsi()
</style>
